package com.example.vae.Activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.example.vae.Adapter.InforViewPagerAdapter;
import com.example.vae.Home.Information.GuanZhuItemFragment;
import com.example.vae.R;

import java.util.ArrayList;
import java.util.List;


//这个 活动也是关于搜索粉丝，@官方评论，加载信息的页面
public class InformationActivity extends AppCompatActivity {

    private List<Fragment> list;
    private ViewPager vp;
    private Button btn1,btn2;
    private InforViewPagerAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_information);
        vp=findViewById(R.id.vp);
        btn1=findViewById(R.id.btn1);
        btn2=findViewById(R.id.btn2);

        list=new ArrayList<>();
        list.add(new GuanZhuItemFragment());
        list.add(new GuanZhuItemFragment());

        adapter=new InforViewPagerAdapter(getSupportFragmentManager(),0,list);
        vp.setAdapter(adapter);
        vp.setCurrentItem(0);

        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                vp.setCurrentItem(0);
                btn1.setTextColor(getResources().getColor(R.color.mr_cast_meta_default_text_color));
                btn2.setTextColor(getResources().getColor(R.color.mr_cast_progressbar_background_dark));
                btn2.setBackgroundColor(getResources().getColor(R.color.mr_cast_progressbar_background_light));
                btn1.setBackgroundColor(getResources().getColor(R.color.mr_cast_progressbar_progress_and_thumb_light));
            }
        });

        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                vp.setCurrentItem(1);
                btn2.setTextColor(getResources().getColor(R.color.mr_cast_meta_default_text_color));
                btn1.setTextColor(getResources().getColor(R.color.mr_cast_progressbar_background_dark));
                btn1.setBackgroundColor(getResources().getColor(R.color.mr_cast_progressbar_background_light));
                btn2.setBackgroundColor(getResources().getColor(R.color.mr_cast_progressbar_progress_and_thumb_light));
            }
        });
//        这里设置viewpage 监听事件，当换页面的时候，进行button 页面的切换
        vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

                switch (position){
                    case 1:
                        btn2.setTextColor(getResources().getColor(R.color.mr_cast_meta_default_text_color));
                        btn1.setTextColor(getResources().getColor(R.color.mr_cast_progressbar_background_dark));
                        btn1.setBackgroundColor(getResources().getColor(R.color.mr_cast_progressbar_background_light));
                        btn2.setBackgroundColor(getResources().getColor(R.color.mr_cast_progressbar_progress_and_thumb_light));
                        break;
                    case 0:
                        btn1.setTextColor(getResources().getColor(R.color.mr_cast_meta_default_text_color));
                        btn2.setTextColor(getResources().getColor(R.color.mr_cast_progressbar_background_dark));
                        btn2.setBackgroundColor(getResources().getColor(R.color.mr_cast_progressbar_background_light));
                        btn1.setBackgroundColor(getResources().getColor(R.color.mr_cast_progressbar_progress_and_thumb_light));
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });


    }
}
